package com.poster.controller;

import com.poster.entity.dto.UserLoginDto;
import com.poster.entity.dto.UserRegisterDto;
import com.poster.entity.vo.ResultVo;
import com.poster.entity.vo.UserProfileVo;
import com.poster.service.IAccountService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Validated
@RestController
@RequestMapping("account")
public class AccountController {


    private final IAccountService accountService;


    public AccountController(IAccountService accountService) {
        this.accountService = accountService;
    }

    @PostMapping("login")
    public ResultVo<UserProfileVo> login(@RequestBody UserLoginDto dto){
        return ResultVo.success(accountService.login(dto));
    }

    @PostMapping("register")
    public ResultVo<Void> register(@Validated @RequestBody UserRegisterDto userRegisterDto){
        accountService.register(userRegisterDto);
        return ResultVo.success();
    }
}
